<template>
  <div class="app">
    <div class="sidebar">
      <div class="sidebar-header">
        <button class="new-chat">
          <span class="plus-icon" @click.stop="showPopup">+</span>
          <span class="new-chat-text" @click="startNewChat">New chat</span>
        </button>
      </div>
      <div class="sidebar-content">
        <div class="models-section">
          <h3>AI Models</h3>
          <div class="model-list">
            <button 
              v-for="model in aiModels" 
              :key="model.id"
              :class="['model-item', { active: currentModel === model.id }]"
              @click="selectModel(model)"
            >
              <span class="model-icon">{{ model.icon }}</span>
              <div class="model-info">
                <div class="model-name">{{ model.name }}</div>
                <div class="model-desc">{{ model.description }}</div>
              </div>
            </button>
          </div>
        </div>
      </div>
    </div>
    <div class="main">
      <ChatArea />
      <ChatInput />
    </div>

    <!-- 弹窗 -->
    <Transition name="fade">
      <div v-if="isPopupVisible" class="popup" @click="hidePopup">
        <div class="popup-content" @click.stop>
          更多功能开发中，敬请期待......
        </div>
      </div>
    </Transition>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import ChatArea from './components/ChatArea.vue'
import ChatInput from './components/ChatInput.vue'
import { useChatStore } from './stores/chat'

const chatStore = useChatStore()
const currentModel = ref('gpt4')
const isPopupVisible = ref(false)

const showPopup = (event) => {
  event.stopPropagation()
  isPopupVisible.value = true
}

const hidePopup = () => {
  isPopupVisible.value = false
}

const startNewChat = () => {
  chatStore.clearHistory()
}

const selectModel = (model) => {
  currentModel.value = model.id
  chatStore.clearHistory()
}

const aiModels = [
  {
    id: 'gpt4',
    name: 'GPT-4',
    description: '最强大的 AI 模型',
    icon: '🧠'
  },
  {
    id: 'gpt35',
    name: 'GPT-3.5',
    description: '快速且高效',
    icon: '⚡'
  },
  {
    id: 'claude',
    name: 'Claude',
    description: '精确的分析能力',
    icon: '🎯'
  },
  {
    id: 'gemini',
    name: 'Gemini',
    description: '谷歌最新模型',
    icon: '🌟'
  }
]
</script>

<style scoped>
.app {
  height: 100vh;
  display: flex;
}

.sidebar {
  width: 260px;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
}

.sidebar-header {
  padding: 12px;
  border-bottom: 1px solid var(--border-color);
}

.new-chat {
  width: 100%;
  padding: 12px;
  background: var(--primary-color);
  color: white;
  border: none;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  font-size: 14px;
  transition: background-color 0.2s;
}

.new-chat:hover {
  background: var(--primary-color-dark);
}

.new-chat span {
  font-size: 20px;
  line-height: 1;
}

.sidebar-content {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
}

.models-section {
  margin-top: 12px;
}

.models-section h3 {
  font-size: 12px;
  color: #666;
  margin-bottom: 8px;
  padding: 0 8px;
}

.model-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.model-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border: none;
  background: transparent;
  border-radius: 6px;
  cursor: pointer;
  transition: background-color 0.2s;
  text-align: left;
  color: inherit;
  width: 100%;
}

.model-item:hover {
  background: rgba(0, 0, 0, 0.05);
}

.model-item.active {
  background: var(--primary-color);
  color: white;
}

.model-icon {
  font-size: 24px;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.1);
  border-radius: 6px;
}

.model-info {
  flex: 1;
}

.model-name {
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 2px;
}

.model-desc {
  font-size: 12px;
  opacity: 0.8;
}

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: white;
}

/* 活动状态下的图标背景 */
.model-item.active .model-icon {
  background: rgba(255, 255, 255, 0.2);
}

/* 修改新聊天按钮样式 */
.new-chat {
  width: 100%;
  padding: 12px;
  background: var(--primary-color);
  color: white;
  border: none;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  font-size: 14px;
  transition: background-color 0.2s;
}

.plus-icon {
  font-size: 20px;
  line-height: 1;
  padding: 2px 6px;
  border-radius: 4px;
  cursor: pointer;
  transition: background-color 0.2s;
}

.plus-icon:hover {
  background: rgba(255, 255, 255, 0.2);
}

.new-chat-text {
  cursor: pointer;
}

/* 弹窗样式 */
.popup {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.popup-content {
  background: white;
  padding: 20px 30px;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  font-size: 16px;
  color: #333;
}

/* 过渡动画 */
.fade-enter-active,
.fade-leave-active {
  transition: opacity 0.3s ease;
}

.fade-enter-from,
.fade-leave-to {
  opacity: 0;
}

.popup-content {
  animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
  from {
    transform: translateY(-20px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}
</style> 